capture log close
clear
use "[data filepath]"

xtset Seller_ID




summarize Reputation
local rep_mean = r(mean)
local rep_sd = r(sd)
local rep_twominus = `rep_mean' - 2 * `rep_sd'
local rep_oneminus = `rep_mean' - `rep_sd'
local rep_oneplus = `rep_mean' + `rep_sd'

summarize Sentiment
local sent_mean = r(mean)
local sent_sd = r(sd)
local sent_twominus = `sent_mean' - 2 * `sent_sd'
local sent_oneminus = `sent_mean' - `sent_sd'
local sent_oneplus = `sent_mean' + `sent_sd'
local sent_twoplus = `sent_mean' + 2 * `sent_sd'
local sent_threeplus = `sent_mean' + 3  * `sent_sd'


summarize price_USD
summarize Sentiment
summarize Reputation
summarize Negative_Sales
summarize Positive_Sales
table Repeat_Sale
summarize Age
summarize Size_in_Grams
table Rx
table UN_Schedule
table MCC
table Location
*Seller ID is a numeric identifier of each individual vendor
*Size in Grams is size in grams of individual sales.
*MCC is top level drug category, labelled.
*UN Schedule is United Nations schedule category, regularized between the two
*schedules to uncategorized, low, medium, and high.
*Month is numeric month of the market.
*Age is how many months a vendor has been active on the market.
*Cumulative sales is how many cumulative sales a vendor has made up to that point.
*Log_Price is the log transformation of the price of a sale.
*Repeat_Sale is a dichotomous variable denoting whether a transaction is the
*first sale between alters or not.
*DEA schedule is schedule as defined by the American DEA, regularized to the 
*same scale as the UN schedule of unscheduled, low, medium, and high.
*Location is the location of the vendor, labelled.
*Rx is a dichotomous variable with a 0 denoting prescription and 1 denoting 
*non-prescription, labelled.
*Positive_Sales 

*Sentiment is discursive reputation
*Reputation is numeric reputation
*Rx 


*Model 1 - Market characteristics
eststo: xtreg Log_Price i.Rx i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic

*Model 2 - Reputation measures
eststo: xtreg Log_Price c.Sentiment c.Reputation i.Rx i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic


*Model 3 - UN Schedule interactions
eststo: xtreg Log_Price i.UN_Schedule##c.Sentiment i.UN_Schedule##c.Reputation i.Rx i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic
margins UN_Schedule, at(Sentiment = (0(5)100))
marginsplot, yline(0, lcolor(blue)) xline(`sent_mean', lpattern(dash) lcolor(red)) xtitle("Discursive Reputation") ytitle("Log Sales Price") title("") text(3.6 6 "Mean", placement(e)) 

margins UN_Schedule, at(Reputation = (0(5)100))

marginsplot, yline(0, lcolor(blue)) xline(`rep_mean', lpattern(dash) lcolor(red)) xtitle("Numeric Reputation") ytitle("Log Sales Price") title("") text(5 89 "Mean", placement(e)) 





*Model 4 - Rx Interactions
eststo: xtreg Log_Price i.Rx##c.Sentiment i.Rx##c.Reputation i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic
margins Rx, at(Sentiment = (0(5)100))
marginsplot, yline(0, lcolor(blue)) xline(`sent_mean', lpattern(dash) lcolor(red)) xtitle("Discursive Reputation") ytitle("Log Sales Price") title("") text(4.5 7 "Mean", placement(e)) 



margins Rx, at(Reputation = (0(5)100))
marginsplot, yline(0, lcolor(blue)) xline(`rep_mean', lpattern(dash) lcolor(red)) xtitle("Numeric Reputation") ytitle("Log Sales Price") title("") text(5.6 89 "Mean", placement(e)) 



*Model 5 - US to US only DEA Schedule 
eststo: xtreg Log_Price i.DEA_Schedule##c.Sentiment i.DEA_Schedule##c.Reputation i.Rx i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales c.Size_in_Grams if USA_Domestic == 1, fe

esttab using"[esttab filepath]", se label b(%10.3f) se(%10.3f) nogap
eststo clear

*Log price per microgram models
*UN Schedule interactions, price per microgram DV
*Model 6
eststo: xtreg Log_Price_Per_Microgram i.UN_Schedule##c.Sentiment i.UN_Schedule##c.Reputation i.Rx i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic
*Rx interactions, price per microgram DV
*Model 7
eststo: xtreg Log_Price_Per_Microgram i.Rx##c.Sentiment i.Rx##c.Reputation i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic
*Price, interaction of MCC and size in grams.
*Model 8 UN Schedule interactions
eststo: xtreg Log_Price i.UN_Schedule##c.Sentiment i.UN_Schedule##c.Reputation i.Rx i.Month c.Age i.MCC##c.Size_in_Grams i.Repeat_Sale c.Cumulative_Sales i.Location, fe
estat ic
*Model 9 Prescription interactions.
eststo: xtreg Log_Price i.Rx##c.Sentiment i.Rx##c.Reputation i.UN_Schedule i.Month c.Age i.MCC##c.Size_in_Grams i.Repeat_Sale c.Cumulative_Sales i.Location, fe
estat ic

esttab using"[esttab filepath]", se label b(%10.3f) se(%10.3f) nogap
eststo clear


*Model 10: UN Schedule Interactions, Numeric Reputation x Sales Quantile 
eststo: xtreg Log_Price i.UN_Schedule##c.Sentiment i.UN_Schedule##c.Reputation c.Reputation#i.Cumu_Sales_Quantile i.Rx i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic

*Model 11: UN Schedule Interactions, Positive and Negative Sales Count
eststo: xtreg Log_Price i.UN_Schedule##c.Sentiment i.UN_Schedule##c.Reputation i.Rx i.Month c.Age i.MCC i.Repeat_Sale c.Positive_Sales c.Negative_Sales i.Location c.Size_in_Grams, fe
estat ic

*Model 12: Rx Interactions, Numeric Reputation x Sales Quantile
eststo: xtreg Log_Price i.Rx##c.Sentiment i.Rx##c.Reputation c.Reputation#i.Cumu_Sales_Quantile i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Cumulative_Sales i.Location c.Size_in_Grams, fe
estat ic

*Model 13: Rx Interactions, Positive and Negative Sales Counts
eststo: xtreg Log_Price i.Rx##c.Sentiment i.Rx##c.Reputation i.UN_Schedule i.Month c.Age i.MCC i.Repeat_Sale c.Positive_Sales c.Negative_Sales i.Location c.Size_in_Grams, fe
estat ic


esttab using"[esttab filepath]", se label b(%10.3f) se(%10.3f) nogap
eststo clear


